/*
    Copyright 2011 - Tommi Laukkanen (www.substanceofcode.com)

    This file is part of NewsFlow.

    NewsFlow is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    NewsFlow is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with NewsFlow. If not, see <http://www.gnu.org/licenses/>.
*/

import Qt 4.7

Item {
    id: errorPanel
    x: 0
    y: 0
    property string reason: ""
    signal showLogin()
    width: parent.width
    height: errorIndicator.height
    state: "hidden"

    Rectangle {
        id: errorIndicator
        x: 10
        y: 10
        width: parent.width - 20
        height: errorItems.height+20
        color: "#222"
        radius: 5
        smooth: true
        border.width: 1
        border.color: "#222"
        state: errorPanel.state //"hidden"

        Row {
            x: 10
            id: errorItems
            anchors.horizontalCenter: parent.horizontalCenter
            anchors.verticalCenter: parent.verticalCenter
            spacing: 10
            width: parent.width

            Image {
                id: errIcon
                source: "../pics/warning_48.png"
            }

            Column {
                width: parent.width - errIcon.width - 30
                spacing: 10

                Text {
                    id: errorText
                    text: "Oops... Something unexpected happened."
                    color: "#eee"
                    wrapMode: Text.WordWrap
                    font.pixelSize: 18
                    width: parent.width
                }

                Text {
                    text: errorPanel.reason
                    color: "#ccc"
                    wrapMode: Text.WordWrap
                    font.pixelSize: 18
                    width: parent.width
                }
            }
        }

        states:
            State {
            name: "hidden"
            PropertyChanges {
                target: errorIndicator
                y: 0 - errorIndicator.height - 1
            }
        }
        State {
            name: "shown"
            PropertyChanges {
                target: errorIndicator
                y: 10
            }
        }

        transitions: Transition {
            SequentialAnimation {
                PropertyAnimation {
                    target: errorIndicator
                    properties: "y"
                    duration: 200
                    easing.type: "InOutCubic"
                }
                PropertyAnimation {
                    target: errorIndicator
                    properties: "y"
                    duration: 5000
                }
                ScriptAction {
                    script: {
                        errorIndicator.state = "hidden";
                        if(reason.indexOf("403")) {
                            errorPanel.showLogin();
                        }
                    }
                }
            }
        }
    }
}
